﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using XNAGameEngine.Input;
using Microsoft.Xna.Framework.Input;
using XNAGameEngine;
using XNAGameEngine.GameState;
using XNAGameEngine.GUI;

namespace XNAGameEngine
{
    class ForceGameOverControl : GUIObject, IInputListener
    {
        public ForceGameOverControl(IManagerGUI guiManager)
            : base(guiManager)
        {
        }

        public override void Initialize()
        {
            base.Initialize();

            GameEngine.GetService<IManagerInput>().ToggleInputListening(true, this);
        }

        public override void Cleanup()
        {
            base.Cleanup();

            GameEngine.GetService<IManagerInput>().ToggleInputListening(false, this);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        #region IInputListener Members

        public void InputPressed(InputMessage input)
        {
            switch (input._key)
            {
                case Keys.Q:
                    Console.WriteLine("Changing to Game Over Lose state");
                    GameEngine.GetService<IManagerGameState>().ChangeState("GameOverLoseState");
                    break;
                case Keys.R:
                    Console.WriteLine("Changing to Game Over Win state");
                    GameEngine.GetService<IManagerGameState>().ChangeState("GameOverState");
                    break;
                case Keys.Escape:
                    Console.WriteLine("Ending Game");
                    GameEngine.GetService<IManagerGameState>().ShutdownEngine();
                    break;
            }
        }

        public void InputReleased(InputMessage input)
        {
        }

        public void InputHeld(InputMessage input)
        {
        }

        public event ManagerInput.InputRegisterListenerEventHandler ThrowUnregisterListenerEvent;

        #endregion
    }
}
